home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Lists.c
-
- Contains: List Manager stuff and associated routines
-
- Written by: Chris White, Developer Technical Support
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 03/29/96 CW First release
-
- */
-
-
- #pragma segment Core
-
-
- // System Includes
-
-
-
- // Application Includes
-
- #ifndef __BAREBONES__
- #include "BareBones.h"
- #endif
-
-
- #ifndef __PROTOTYPES__
- #include "Prototypes.h"
- #endif
-
-
-
-
-
- static ControlRef gControl;
- static SInt32 gValueSlop;
- static SInt32 gSaveValue;
- static SInt32 gStartValue;
- static RgnHandle gSaveClip = nil;
-
-
-
- static SInt32 CalcValueFromPoint ( ControlRef theControl, Point thePoint );
- static void DisableDrawing ( void );
- static void EnableDrawing ( void );
-
-
-
-
-
- OSErr BeginThumbTracking ( ControlRef theControl )
- {
- const SInt32 kMinLowMem = 512;
-
- OSErr theErr = noErr;
- Size theGrow;
- Point thePoint;
-
- gControl = theControl;
- gStartValue = GetControlValue ( theControl );
-
- gValueSlop = 0;
- GetMouse ( &thePoint );
- gValueSlop = GetControlValue ( theControl ) - CalcValueFromPoint ( theControl, thePoint );
-
- // Preflight memory for call to NewRgn
- if ( MaxMem ( &theGrow ) < kMinLowMem )
- {
- theErr = memFullErr;
- goto CleanupAndBail;
- }
- gSaveClip = NewRgn ( );
-
- DisableDrawing ( );
-
- CleanupAndBail:
- // Don't have to do any cleanup here
-
- return theErr;
- }
-
-
-
- void EndThumbTracking ( void )
- {
- EnableDrawing ( );
-
- DisposeRgn ( gSaveClip );
- SetControlValue ( gControl, gSaveValue );
-
- return;
- }
-
-
-
- pascal void ScrollThumbActionProc ( void )
- {
- SInt32 theValue;
- WindowRef theWindow;
- ControlRef theControl = gControl;
- Point thePoint;
- Rect theRect;
- tWindowInfoPtr theInfo;
-
-
- theWindow = (*theControl)->contrlOwner;
- theInfo = (tWindowInfoPtr) GetWRefCon ( theWindow );
-
- #if DEBUGGING
- if ( theInfo == nil ) DebugStr ( "\p theInfo == nil" );
- #endif
-
- theRect = (*theControl)->contrlRect;
- if ( theControl == theInfo->hScrollBar )
- InsetRect ( &theRect, -kThumbTrackLengthSlop, -kThumbTrackWidthSlop );
- else
- InsetRect ( &theRect, -kThumbTrackWidthSlop, -kThumbTrackLengthSlop );
-
- // Assumes the port is correctly set up
- GetMouse ( &thePoint );
- if ( PtInRect ( thePoint, &theRect ) )
- theValue = CalcValueFromPoint ( theControl, thePoint );
- else
- theValue = gStartValue;
-
- if ( theValue != GetControlValue ( theControl ) )
- {
- EnableDrawing ( );
-
- gSaveValue = theValue;
- SetControlValue ( theControl, theValue );
- UpdateWindowContent ( theWindow );
-
- DisableDrawing ( );
-
- }
-
- return;
- }
-
-
-
- pascal void ScrollControlActionProc ( ControlRef theControl, SInt16 thePart )
- {
- WindowRef theWindow;
- tWindowInfoPtr theInfo;
- SInt32 theValue,
- theDistance,
- limitValue;
-
-
- theWindow = (*theControl)->contrlOwner;
- theInfo = (tWindowInfoPtr) GetWRefCon ( theWindow );
-
- #if DEBUGGING
- if ( theInfo == nil ) DebugStr ( "\p theInfo == nil" );
- #endif
-
-
- switch ( thePart )
- {
- case inUpButton:
- case inDownButton:
- theDistance = 10;
- break;
-
- case inPageUp:
- case inPageDown:
- if ( theControl == theInfo->hScrollBar )
- theDistance = (theWindow->portRect.right - theWindow->portRect.left)
- - kScrollBarWidth - kPageOverlap;
- else
- theDistance = (theWindow->portRect.bottom - theWindow->portRect.top)
- - kScrollBarWidth - kPageOverlap;
- break;
- }
-
- theValue = GetControlValue ( theControl );
-
- switch ( thePart )
- {
- case inUpButton:
- case inPageUp:
- limitValue = GetControlMinimum ( theControl );
- if ( theValue - theDistance < limitValue )
- theValue = limitValue;
- else
- theValue -= theDistance;
- break;
-
- case inDownButton:
- case inPageDown:
- limitValue = GetControlMaximum ( theControl );
- if ( theValue + theDistance > limitValue )
- theValue = limitValue;
- else
- theValue += theDistance;
- break;
- }
-
- SetControlValue ( theControl, theValue );
- UpdateWindowContent ( theWindow );
-
- return;
- }
-
-
-
- static SInt32 CalcValueFromPoint ( ControlRef theControl, Point thePoint )
- {
- SInt32 theValue,
- theRange,
- theDistance,
- thePin;
- Rect theRect;
- WindowRef theWindow;
- tWindowInfoPtr theInfo;
-
-
- theWindow = (*theControl)->contrlOwner;
- theInfo = (tWindowInfoPtr) GetWRefCon ( theWindow );
-
- #if DEBUGGING
- if ( theInfo == nil ) DebugStr ( "\p theInfo == nil" );
- #endif
-
- theRect = (*theControl)->contrlRect;
- theRange = GetControlMaximum ( theControl ) - GetControlMinimum ( theControl );
- if ( theControl == theInfo->vScrollBar )
- {
- // Scroll distance adjusted for scroll arrows and the thumb
- theDistance = theRect.bottom - theRect.top - kTotalWidthAdjust;
-
- // Pin thePoint to the middle of the thumb
- thePin = theRect.top + (kTotalWidthAdjust / 2);
-
- theValue = ((thePoint.v - thePin) * theRange) / theDistance;
- }
- else
- {
- // Scroll distance adjusted for scroll arrows and the thumb
- theDistance = theRect.right - theRect.left - kTotalWidthAdjust;
-
- // Pin thePoint to the middle of the thumb
- thePin = theRect.left + (kTotalWidthAdjust / 2);
-
- theValue = ((thePoint.h - thePin) * theRange) / theDistance;
- }
-
- theValue += gValueSlop;
-
-
- if ( theValue < GetControlMinimum ( theControl ) )
- theValue = GetControlMinimum ( theControl );
- else if ( theValue > GetControlMaximum ( theControl ) )
- theValue = GetControlMaximum ( theControl );
-
- return theValue;
- }
-
-
-
- static void DisableDrawing ( void )
- {
- Rect nullRect = { 0, 0, 0, 0 };
-
- GetClip ( gSaveClip );
- ClipRect ( &nullRect );
-
- return;
- }
-
-
-
- static void EnableDrawing ( void )
- {
- SetClip ( gSaveClip );
-
- return;
- }
-